package model

import (
	"time"
)

type Product struct {
	ID string `json:"id" gorm:"column:id"`
	Name string `json:"name" gorm:"column:name"`
	CreateTime time.Time `json:"ctime" gorm:"column:create_time"`
}

func (p *Product)TableName() string{
	return `tb_product`
}

func (p *Product) CreateProduct() error{
	return DB.Self.Create(p).Error
}

func (p *Product) UpdateProduct() error{
	return DB.Self.Update(p).Error
}

func (p *Product) DeleteProduct() error{
	return DB.Self.Delete(&p).Error
}

func GetProductList() ([]*Product,error){
	lists := make([]*Product,0)
	err := DB.Self.Where("").Order("id desc").Find(&lists).Error
	if err!=nil{
		return nil,err
	}
	return lists,err
}

